package com.ks.core.validation;

import com.ks.core.anno.MustEq;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author kingdee
 */
public class MustEqValidator implements ConstraintValidator<MustEq, String> {

    private String compaireValue;

    @Override
    public void initialize(MustEq constraintAnnotation) {
        compaireValue = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return StringUtils.isBlank(compaireValue) || compaireValue.equals(value);
    }
}
